package com.ruoyi.course.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.AcademicYear;
import com.ruoyi.course.service.IAcademicYearService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学年信息Controller
 * 
 * @author chenxl
 * @date 2025-08-29
 */
@RestController
@RequestMapping("/course/year")
public class AcademicYearController extends BaseController
{
    @Autowired
    private IAcademicYearService academicYearService;

    /**
     * 查询学年信息列表
     */
   // @PreAuthorize("@ss.hasPermi('course:year:list')")
    @GetMapping("/list")
    public TableDataInfo list(AcademicYear academicYear)
    {
        startPage();
        List<AcademicYear> list = academicYearService.selectAcademicYearList(academicYear);
        return getDataTable(list);
    }

    /**
     * 导出学年信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:year:export')")
    @Log(title = "学年信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AcademicYear academicYear)
    {
        List<AcademicYear> list = academicYearService.selectAcademicYearList(academicYear);
        ExcelUtil<AcademicYear> util = new ExcelUtil<AcademicYear>(AcademicYear.class);
        util.exportExcel(response, list, "学年信息数据");
    }

    /**
     * 获取学年信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:year:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(academicYearService.selectAcademicYearById(id));
    }

    /**
     * 新增学年信息
     */
    @PreAuthorize("@ss.hasPermi('course:year:add')")
    @Log(title = "学年信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AcademicYear academicYear)
    {
        return toAjax(academicYearService.insertAcademicYear(academicYear));
    }

    /**
     * 修改学年信息
     */
    @PreAuthorize("@ss.hasPermi('course:year:edit')")
    @Log(title = "学年信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AcademicYear academicYear)
    {
        return toAjax(academicYearService.updateAcademicYear(academicYear));
    }

    /**
     * 删除学年信息
     */
    @PreAuthorize("@ss.hasPermi('course:year:remove')")
    @Log(title = "学年信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(academicYearService.deleteAcademicYearByIds(ids));
    }
}
